package kr.hkit.powerjava.chapter22.work2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import kr.hkit.powerjava.chapter22.work2.dao.DepartmentManagerImpl;
import kr.hkit.powerjava.chapter22.work2.dao.StudentManagerImpl;
import kr.hkit.powerjava.chapter22.work2.vo.Department;
import kr.hkit.powerjava.chapter22.work2.vo.Student;

public class TestMain {
	public static void main(String[] args) {
		//HashMap
		Map<Integer, Department> map = new HashMap<>();
		map.put(1, new Department(1, "컴공", 5));
		map.put(2, new Department(2, "헬정", 3));
		map.put(3, new Department(3, "유교", 2));
		map.put(4, new Department(4, "국통", 6));
		
		System.out.println(map);
		
		map.remove(1);		//키1 삭제
		
		map.put(3, new Department(3, "유교", 1));		//대치값
		
		System.out.println(map.get(3));			//하나의 값 참조
		
		for(Map.Entry<Integer, Department> m : map.entrySet()){			//모든 항목 방문.출력
			Integer key = m.getKey();
			Department value = m.getValue();
			System.out.println("key= " + key + "value= " + value);
		}
		
		//		
		ArrayList<Student> stdList = new ArrayList<>();
		ArrayList<Department> deptList = new ArrayList<>();
		StudentManagerImpl sm = new StudentManagerImpl(stdList);
		DepartmentManagerImpl dm = new DepartmentManagerImpl(deptList);
		
		//추가
		Student std1 = new Student(1,"김태희",90,90,90);
		sm.addItem(std1);
		Student std2 = new Student(2,"제시카",89,79,77);
		sm.addItem(std2);
		sm.addItem(new Student(3,"김주하",85,92,34));
		sm.addItem(new Student(4,"이민정",95,23,52));
		sm.addItem(std1);
		
		Department dept = new Department(1, "컴공", 5);
		dm.addItem(dept);
		dm.addItem(new Department(2, "헬정", 3));
		dm.addItem(new Department(3, "유교", 2));//유아교육과
		dm.addItem(new Department(4, "국통", 6));//국제통상학과 추추 
		
		//삭제
		/*sm.delItem(std1);
		sm.delItem(std2);*/
		
		//검색
		/*Student searchItem = new Student(3, "김태희");
		String result = sm.searchItem(searchItem)?"존재" : "없음";
		System.out.println(searchItem.getStdNum() + " : " + searchItem.getStdName() + " = " + result);
		*/
		Department searchItem = new Department(2, "헬정");
		String result = dm.searchItem(searchItem)?"존재" : "없음";
//		System.out.println(searchItem.getDeptNo() + " : " + searchItem.getDeptName() + " = " + result);
		
		//수정
		/*Student updateItem = new Student(1, "김태희", 91, 93, 94);
		sm.updateItem(updateItem);*/
		Department updateItem = new Department(2, "헬정", 9);
		dm.updateItem(updateItem);
		
		//출력
//		sm.prnItems();
//		dm.prnItems();
	/*	
		System.out.println("층수순 정렬");
		Comparator<Department> flr = new Comparator<Department>() {

			@Override
			public int compare(Department o1, Department o2) {
				return o1.getFloor() - o2.getFloor();
			}
		};
		dm.prnItems(flr);
		
		System.out.println("총점순 정렬(내림차순)");
		Comparator<Student> totalCom = new Comparator<Student>() {

			@Override
			public int compare(Student o1, Student o2) {
				return (int) (o2.getTotal() - o1.getTotal());
			}
			
		};
		sm.prnItems(totalCom);
		
		System.out.println("이름순 정렬(오름차순)");
		Comparator<Student> com = new Comparator<Student>() {

			@Override
			public int compare(Student o1, Student o2) {
				return o1.getStdName().hashCode() - o2.getStdName().hashCode();
			}
		};
		sm.prnItems(com);
		
		System.out.println("국어점수 정렬(내림차순)");
		Comparator<Student> kor = new Comparator<Student>() {

			@Override
			public int compare(Student o1, Student o2) {
				return o2.getKor() - o1.getKor();
			}
		};
		sm.prnItems(kor);
		sm.prnItems(new Comparator<Student>() {
		@Override
			public int compare(Student o1, Student o2) {
				return o2.getKor() - o1.getKor();
			}			
		});
		
		
		for(Student std : stdList){
			System.out.println(std);
		}
		
		Collections.shuffle(stdList);
		System.out.println("반복자=================");
		Student std = null;
		Iterator<Student> iterator = stdList.iterator();
		while(iterator.hasNext()){
			std = iterator.next();
			System.out.println(std);
		}*/
	}
}
